﻿using Framework;
using UnityEngine;

namespace Game
{
    public class ScenePlayerTrackActionable : IBTreeActionable<SceneObjectBTContext>
    {
        public void OnStart(SceneObjectBTContext context)
        {
            ScenePlayerBTContext playerBtContext = (ScenePlayerBTContext) context;
            context.sceneObject.SetFlipY(playerBtContext.trackObject.position.x < context.sceneObject.position.x);
            context.sceneObject.GetComponent<SceneObjectActionComponent>().SetTrigger(SceneObjectActions.Run);
            context.sceneObject.GetComponent<SceneObjectMoveComponent>().StartMove();
        }

        public void OnEnd(SceneObjectBTContext context)
        {
            context.sceneObject.GetComponent<SceneObjectMoveComponent>().StopMove();
        }

        public TaskStatus Update(SceneObjectBTContext context)
        {
            return TaskStatus.Running;
        }
    }
}